Fast, Combined Forwards-Backwards Pass Global Optimization Framework for Dynamic Compilers

ABSTRACT

The various aspects provide a dynamic compilation framework that includes a machine-independent optimization module operating on a computing device and methods for optimizing code with the machine-independent optimization module using a single, combined-forwards-backwards pass of the code. In the various aspects, the machine-independent optimization module may generate a graph of nodes from the IR, optimize nodes in the graph using forwards and backwards optimizations, and propagating the forwards and backwards optimizations to nodes in a bounded subgraph recognized or defined based on the position of the node currently being optimized. In the various aspects, the machine-independent optimization module may optimize the graph by performing forwards and/or backwards optimizations during a single pass through the graph, thereby achieving an effective degree of optimization and shorter overall compile times. Thus, the various aspects may provide a global optimization framework for dynamic compilers that is faster and more efficient than existing solutions.

RELATED APPLICATIONS

This application is a continuation of U.S. patent application Ser. No.14/034,770 entitled “Fast, Combined Forwards-Backwards Pass GlobalOptimization Framework for Dynamic Compilers” filed Sep. 24, 2013, theentire contents of which are incorporated herein by reference.

BACKGROUND

Generally, the compilation of a software application program may beperformed in two steps: the first step before distribution and thesecond step after distribution, such as at the time of execution. Thistwo-part compilation allows the software application to be distributedas bytecode (e.g., Dalvik bytecode) so that an optimizer may optimizethe code for the specific machine on which the code is to be executed.As an example, Dalvik is a process virtual machine (VM) on the Google™Android operating system that converts Dalvik bytecode to ARM executableobject code prior to execution. This system allows the softwareapplications to be easily ported to any computing device havingvirtualization software (e.g., Dalvik) that supports the instruction setarchitecture used by the first compiler, regardless of the device'sunderlying hardware and operating system interface.

Currently, an off-line compiler may parse an entire software applicationprogram and generate an intermediate representation (IR) to representthe program structure. This IR typically carries extra information, suchas annotations on the abstract syntax tree, which may be used at codegeneration time by a dynamic or just-in-time (JIT) compiler to analyzeand optimize the program, such as by determining the parts of theprogram that will not be executed in the current environment andremoving such code (i.e., identifying code that will never be executedbecause it is not reachable on any path from start to end of the programin the current implementation or activation circumstance).

In dynamic languages, such as JavaScript, the parsing and compilationoccurs at run-time, just before program execution. Parsing is theprocess of analyzing a text to determine its grammatical structure withrespect to a given formal grammar, and in the interpretation ofprograms, parsing includes reading in the source script and convertingit into an intermediate representation based on the language semanticsof the program language. For most dynamic and/or scripting languages,parsing generates a bytecode representation of the program that is fedinto an interpreter, which may invoke a just-in-time compiler togenerate machine code for selected portions of the code.

Thus, for both static and dynamic languages, a just-in-time (JIT)compiler may analyze and optimize the program to generatemore-performant binary or machine code. Since such optimizations areperformed at runtime, the compilation processing time becomes part ofthe overall program execution time.

Modern JIT compilers may implement any of a number ofmachine-independent, global compiler optimizations to generate themore-performant binary code. Such optimizations include Dead CodeElimination (DCE), Sparse Conditional Constant Propagation (SCCP),Algebraic Simplification (AS), and Global Value Numbering (GVN), each ofwhich may be classified as being either a “forwards pass” optimizationor a “backwards pass” optimization.

Many JIT compilers implement each of these optimizations as individualpasses over the Internal Representation (IR) of the input program.Another approach is to combine these optimizations into a singleframework and have an iterative (i.e., multiple forwards followed bybackwards passes or vice versa) fixed-point solution.

However, current solutions are not suitable for use in constrainedcomputing environments, such as in mobile devices, which have limitedprocessing and/or battery resources. Iterative point solutions may alsotake so long to complete that the user's experience is adverselyaffected when the user attempts to launch an application. For example,while the iterative solution has been shown to produce highly optimizedcode, the iterative solution suffers from the drawback of potentiallytaking a large number of iterations over the IR. As such, this solutionis not very appropriate for a JIT compiler in the mobile domain wherespeed of compilation (and responsiveness to an application) is veryimportant.

SUMMARY

The various aspects provide a dynamic compilation framework thatincludes a machine-independent optimization module operating on acomputing device and methods for optimizing code with themachine-independent optimization module using a single,combined-forwards-backwards pass of the code. In the various aspects,the machine-independent optimization module may generate a graph ofnodes from the IR of code, optimize nodes in the graph using forwardsand backwards optimizations, and propagating the forwards and backwardsoptimizations to nodes in a bounded subgraph recognized or defined basedon the position of the node currently being optimized. In the variousaspects, the machine-independent optimization module may optimize thegraph by performing forwards and/or backwards optimizations during asingle pass through the graph, thereby achieving an effective degree ofoptimization and shorter overall compile times. Thus, the variousaspects may provide a global optimization framework for dynamiccompilers that is faster and more efficient than existing solutions.

The machine-independent optimization module may begin by optimizing astart node in the graph and traversing the graph in a forwards manner,applying one or more forwards optimizations and/or backwardsoptimizations to each node that may benefit from such optimizations. Inanother aspect, for each visited node, the machine-independentoptimization module may propagate applied forwards optimizations to thevisited node's successors and applied backwards optimizations to thevisited node's predecessors. The machine-independent optimization modulemay limit such propagations to nodes within a bounded subgraph that hasbeen recognized or defined around the visited node.

In another aspect, the machine-independent optimization module maymaintain a count of the total number of times each node in the graph hasbeen visited (i.e., optimized). In such an aspect, themachine-independent optimization module may ensure that the nodes in thegraph are visited no more than two times, thereby ensuring manageableoptimization times. Thus, the machine-independent optimization modulemay continue the single-pass, forwards/backwards optimization processuntil all nodes in the graph are optimized, eliminated, or visitedtwice. By limiting the process to visiting/optimizing nodes no more thantwo times, the various aspects enable code optimization that is fasterthan existing iterative solutions (i.e., exhibiting shorter compiletimes) while providing code optimizations that are on par with currentiterative optimization techniques.

The various aspects include a method of optimizing an intermediaterepresentation of source code by generating a graph from theintermediate representation wherein the graph includes a plurality ofnodes, selecting a node in the graph, applying an optimization to theselected node, recognizing a bounded subgraph based on the selectednode, and propagating the optimization to nodes in the bounded subgraph.In an aspect, recognizing a bounded subgraph based on the selected nodemay include identifying an entry node, wherein the entry node is apredecessor node of the selected node, scanning through the graph,determining whether an exit node is detected wherein an exit node is asuccessor node of the selected node, and defining the bounded subgraphbased on the entry node and the exit node in response to determiningthat an exit node is detected. In another aspect, the method may alsoinclude determining whether there is an unvisited node in the graph andselecting an unvisited node for optimization in response to determiningthat there is an unvisited node in the graph.

In an aspect, selecting a node in the graph may include initializing aready list, adding a start node to the ready list, selecting a node inthe ready list, and incrementing a visitation counter of the selectednode. In another aspect, selecting a node in the ready list may includedetermining whether there is a control flow node in the ready list,selecting the control flow node in response to determining that acontrol flow node is in the ready list, and selecting a data node inresponse to determining that there are no control flow nodes in theready list. In another aspect, selecting a node in the ready list mayinclude sorting nodes in the ready list into a reverse postordering andselecting a first node in the reverse postordering.

In an aspect, the method may also include adding successors of theselected node to the ready list and removing the selected node from theready list. In another aspect, adding successors of the selected node tothe ready list may include, for each of the selected node's successors,determining whether predecessors of a successor node have all beenvisited and adding the successor node to the ready list in response todetermining that the successor node's predecessors have all beenvisited.

In an aspect, applying an optimization to the selected node may includedetermining whether the selected node has been visited more than twice.In another aspect, the method may also include determining whether toapply a forwards optimization on the selected node in response todetermining that the selected node has not been visited more than twice,applying the forwards optimization on the selected node in response todetermining to apply the forwards optimization on the selected node,determining whether to apply a backwards optimization on the selectednode in response to determining that the selected node has not beenvisited more than twice, and applying the backwards optimization on theselected node in response to determining to apply the backwardsoptimization. In another aspect, propagating the optimization to nodesin the bounded subgraph may include propagating the forwardsoptimization through the bounded subgraph of the selected node inresponse to determining to apply the forwards optimization on theselected node and propagating the backwards optimization through thebounded subgraph of the selected node in response to determining toapply the backwards optimization on the selected node.

In another aspect, propagating the forwards optimization through thebounded subgraph of the selected node may include initializing asuccessor list, adding all successors of the selected node to thesuccessor list, choosing a successor node from the successor list,incrementing a visitation counter of the chosen successor node,determining whether the chosen successor node has been visited more thantwice, determining whether to apply the forwards optimization on thechosen successor node in response to determining that the chosensuccessor node has not been visited twice, applying the forwardsoptimization on the chosen successor node in response to determining toapply the forwards optimization, determining whether the chosensuccessor node is an exit node, adding successors of the chosensuccessor node to the successor list unless it is determined that thechosen successor node is an exit node or it is determined not to applythe forwards optimization on the chosen successor node, and removing thechosen successor node from the successor list. In another aspect, themethod may also include determining whether the successor list is emptyand selecting another successor node in the successor list in responseto determining that the successor list is not empty.

In an aspect, propagating the backwards optimization through the boundedsubgraph of the selected node may include initializing a predecessorlist, adding all predecessors of the selected node to the predecessorlist, choosing a predecessor node from the predecessor list,incrementing a visitation counter of the chosen predecessor node,determining whether the chosen predecessor node has been visited morethan twice, determining whether to apply the backwards optimization onthe chosen predecessor node in response to determining that the chosenpredecessor node has not been visited twice, applying the backwardsoptimization on the chosen predecessor node in response to determiningto apply the backwards optimization, determining whether the chosenpredecessor node is an entry node, adding a predecessor of the chosenpredecessor node to the predecessor list unless it is determined thatthe chosen predecessor node is an entry node or it is determined not toapply the backwards optimization on the chosen predecessor node, andremoving the chosen predecessor node from the predecessor list. Inanother aspect, the method may also include determining whether thepredecessor list is empty and selecting another predecessor node in thepredecessor list in response to determining that the predecessor list isnot empty.

In an aspect, the method may also include determining whether the readylist is empty and selecting another node in the ready list foroptimization in response to determining that the ready list is notempty. In another aspect, the method may include determining whether allnodes in the graph have been visited in response to determining that theready list is empty and adding an unvisited node to the ready list inresponse to determining that all nodes in the graph have not beenvisited. In yet another aspect, adding an unvisited node to the readylist may include scanning the graph for unvisited nodes, determiningwhether a phi node in the graph has not been visited, selecting the phinode in response to determining that the phi node has not been visited,selecting another unvisited node in response to determining that thereare no unvisited phi nodes, and adding the selected node to the readylist. In another aspect, adding an unvisited node to the ready list mayinclude scanning the graph for unvisited nodes, sorting the unvisitednodes into a reverse postordering, selecting a first node in the reversepostordering, and adding the selected node to the ready list.

Further aspects include a computing device that may include a memory anda processor coupled to the memory, wherein the processor may beconfigured with processor-executable instructions to perform operationsthat include generating a graph from an intermediate representation ofsource code, wherein the graph includes a plurality of nodes, selectinga node in the graph, applying an optimization to the selected node,recognizing a bounded subgraph based on the selected node, andpropagating the optimization to nodes in the bounded subgraph. Inanother aspect, the processor may be configured withprocessor-executable instructions to perform operations such thatrecognizing a bounded subgraph based on the selected node includesidentifying an entry node, wherein the entry node is a predecessor nodeof the selected node, scanning through the graph, determining whether anexit node is detected, wherein an exit node is a successor node of theselected node, and defining the bounded subgraph based on the entry nodeand the exit node in response to determining that an exit node isdetected. In another aspect, the processor may be configured withprocessor-executable instructions to perform operations that includedetermining whether there is an unvisited node in the graph, andselecting an unvisited node for optimization in response to determiningthat there is an unvisited node in the graph.

In an aspect, the processor may be configured with processor-executableinstructions to perform operations such that selecting a node in thegraph includes initializing a ready list, adding a start node to theready list, selecting a node in the ready list, and incrementing avisitation counter of the selected node. In another aspect the processormay be configured with processor-executable instructions to performoperations such that selecting a node in the ready list includesdetermining whether there is a control flow node in the ready list,selecting the control flow node in response to determining that acontrol flow node is in the ready list, and selecting a data node inresponse to determining that there are no control flow nodes in theready list. In another aspect, the processor may be configured withprocessor-executable instructions to perform operations such thatselecting a node in the ready list includes sorting nodes in the readylist into a reverse postordering and selecting a first node in thereverse postordering.

In an aspect, the processor may be configured with processor-executableinstructions to perform operations that include adding successors of theselected node to the ready list and removing the selected node from theready list. In another aspect, the processor may be configured withprocessor-executable instructions to perform operations such that addingsuccessors of the selected node to the ready list includes, for each ofthe selected node's successors, determining whether predecessors of asuccessor node have all been visited and adding the successor node tothe ready list in response to determining that the successor node'spredecessors have all been visited.

In another aspect, the processor may be configured withprocessor-executable instructions to perform operations such thatapplying an optimization to the selected node includes determiningwhether the selected node has been visited more than twice. In a furtheraspect, the processor may be configured with processor-executableinstructions to perform operations that include determining whether toapply a forwards optimization on the selected node in response todetermining that the selected node has not been visited more than twice,applying the forwards optimization on the selected node in response todetermining to apply the forwards optimization on the selected node,determining whether to apply a backwards optimization on the selectednode in response to determining that the selected node has not beenvisited more than twice, and applying the backwards optimization on theselected node in response to determining to apply the backwardsoptimization.

In an aspect, the processor may be configured with processor-executableinstructions to perform operations such that propagating theoptimization to nodes in the bounded subgraph includes propagating theforwards optimization through the bounded subgraph of the selected nodein response to determining to apply the forwards optimization on theselected node and propagating the backwards optimization through thebounded subgraph of the selected node in response to determining toapply the backwards optimization on the selected node. In anotheraspect, the processor may be configured with processor-executableinstructions to perform operations such that propagating the forwardsoptimization through the bounded subgraph of the selected node includesinitializing a successor list, adding all successors of the selectednode to the successor list, choosing a successor node from the successorlist, incrementing a visitation counter of the chosen successor node,determining whether the chosen successor node has been visited more thantwice, determining whether to apply the forwards optimization on thechosen successor node in response to determining that the chosensuccessor node has not been visited twice, applying the forwardsoptimization on the chosen successor node in response to determining toapply the forwards optimization, determining whether the chosensuccessor node is an exit node, adding successors of the chosensuccessor node to the successor list unless it is determined that thechosen successor node is an exit node or it is determined not to applythe forwards optimization on the chosen successor node, and removing thechosen successor node from the successor list. In another aspect, theprocessor may be configured with processor-executable instructions toperform operations that include determining whether the successor listis empty, and selecting another successor node in the successor list inresponse to determining that the successor list is not empty.

In an aspect, the processor may be configured with processor-executableinstructions to perform operations such that propagating the backwardsoptimization through the bounded subgraph of the selected node includesinitializing a predecessor list, adding all predecessors of the selectednode to the predecessor list, choosing a predecessor node from thepredecessor list, incrementing a visitation counter of the chosenpredecessor node, determining whether the chosen predecessor node hasbeen visited more than twice, determining whether to apply the backwardsoptimization on the chosen predecessor node in response to determiningthat the chosen predecessor node has not been visited twice, applyingthe backwards optimization on the chosen predecessor node in response todetermining to apply the backwards optimization, determining whether thechosen predecessor node is an entry node, adding a predecessor of thechosen predecessor node to the predecessor list unless it is determinedthat the chosen predecessor node is an entry node or it is determinednot to apply the backwards optimization on the chosen predecessor node,and removing the chosen predecessor node from the predecessor list. Inanother aspect, the processor may be configured withprocessor-executable instructions to perform operations that includedetermining whether the predecessor list is empty, and selecting anotherpredecessor node in the predecessor list in response to determining thatthe predecessor list is not empty.

In an aspect, the processor may be configured with processor-executableinstructions to perform operations that include determining whether theready list is empty and selecting another node in the ready list foroptimization in response to determining that the ready list is notempty. In another aspect, the processor may be configured withprocessor-executable instructions to perform operations that includedetermining whether all nodes in the graph have been visited in responseto determining that the ready list is empty and adding an unvisited nodeto the ready list in response to determining that all nodes in the graphhave not been visited. In a further aspect, the processor may beconfigured with processor-executable instructions to perform operationssuch that adding an unvisited node to the ready list includes scanningthe graph for unvisited nodes, determining whether a phi node in thegraph has not been visited, selecting the phi node in response todetermining that the phi node has not been visited, selecting anotherunvisited node in response to determining that there are no unvisitedphi nodes, and adding the selected node to the ready list. In anotheraspect, the processor may be configured with processor-executableinstructions to perform operations such that adding an unvisited node tothe ready list includes scanning the graph for unvisited nodes, sortingthe unvisited nodes into a reverse postordering, selecting a first nodein the reverse postordering, and adding the selected node to the readylist.

Further aspects may include a computing device including means forgenerating a graph from an intermediate representation of source codewherein the graph includes a plurality of nodes, means for selecting anode in the graph, means for applying an optimization to the selectednode means for recognizing a bounded subgraph based on the selectednode, and means for propagating the optimization to nodes in the boundedsubgraph. In another aspect, means for recognizing a bounded subgraphbased on the selected node may include means for identifying an entrynode, wherein the entry node is a predecessor node of the selected node,means for scanning through the graph, means for determining whether anexit node is detected, wherein an exit node is a successor node of theselected node, and means for defining the bounded subgraph based on theentry node and the exit node in response to determining that an exitnode is detected. In another aspect, the computing device may includemeans for determining whether there is an unvisited node in the graphand means for selecting an unvisited node for optimization in responseto determining that there is an unvisited node in the graph.

In an aspect, means for selecting a node in the graph may include meansfor initializing a ready list, means for adding a start node to theready list, means for selecting a node in the ready list, and means forincrementing a visitation counter of the selected node. In anotheraspect, means for selecting a node in the ready list may include meansfor determining whether there is a control flow node in the ready list,means for selecting the control flow node in response to determiningthat a control flow node is in the ready list, and means for selecting adata node in response to determining that there are no control flownodes in the ready list. In another aspect, means for selecting a nodein the ready list may include means for sorting nodes in the ready listinto a reverse postordering and means for selecting a first node in thereverse postordering.

In an aspect, the computing device may include means for addingsuccessors of the selected node to the ready list and means for removingthe selected node from the ready list. In another aspect, means foradding successors of the selected node to the ready list may includemeans for, for each of the selected node's successors, determiningwhether predecessors of a successor node have all been visited and meansfor adding the successor node to the ready list in response todetermining that the successor node's predecessors have all beenvisited. In another aspect, means for applying an optimization to theselected node may include means for determining whether the selectednode has been visited more than twice.

In an aspect, the computing device may include means for determiningwhether to apply a forwards optimization on the selected node inresponse to determining that the selected node has not been visited morethan twice, means for applying the forwards optimization on the selectednode in response to determining to apply the forwards optimization onthe selected node, means for determining whether to apply a backwardsoptimization on the selected node in response to determining that theselected node has not been visited more than twice, and means forapplying the backwards optimization on the selected node in response todetermining to apply the backwards optimization. In another aspect,means for propagating the optimization to nodes in the bounded subgraphmay include means for propagating the forwards optimization through thebounded subgraph of the selected node in response to determining toapply the forwards optimization on the selected node and means forpropagating the backwards optimization through the bounded subgraph ofthe selected node in response to determining to apply the backwardsoptimization on the selected node.

In an aspect, means for propagating the forwards optimization throughthe bounded subgraph of the selected node may include means forinitializing a successor list, means for adding all successors of theselected node to the successor list, means for choosing a successor nodefrom the successor list, means for incrementing a visitation counter ofthe chosen successor node, means for determining whether the chosensuccessor node has been visited more than twice, means for determiningwhether to apply the forwards optimization on the chosen successor nodein response to determining that the chosen successor node has not beenvisited twice, means for applying the forwards optimization on thechosen successor node in response to determining to apply the forwardsoptimization, means for determining whether the chosen successor node isan exit node, means for adding successors of the chosen successor nodeto the successor list unless it is determined that the chosen successornode is an exit node or it is determined not to apply the forwardsoptimization on the chosen successor node, and means for removing thechosen successor node from the successor list. In another aspect, thecomputing device may include means for determining whether the successorlist is empty and means for selecting another successor node in thesuccessor list in response to determining that the successor list is notempty.

In an aspect, means for propagating the backwards optimization throughthe bounded subgraph of the selected node may include means forinitializing a predecessor list, means for adding all predecessors ofthe selected node to the predecessor list, means for choosing apredecessor node from the predecessor list, means for incrementing avisitation counter of the chosen predecessor node, means for determiningwhether the chosen predecessor node has been visited more than twice,means for determining whether to apply the backwards optimization on thechosen predecessor node in response to determining that the chosenpredecessor node has not been visited twice, means for applying thebackwards optimization on the chosen predecessor node in response todetermining to apply the backwards optimization, means for determiningwhether the chosen predecessor node is an entry node, means for adding apredecessor of the chosen predecessor node to the predecessor listunless it is determined that the chosen predecessor node is an entrynode or it is determined not to apply the backwards optimization on thechosen predecessor node, and means for removing the chosen predecessornode from the predecessor list. In another aspect, the computing devicemay include means for determining whether the predecessor list is empty,and means for selecting another predecessor node in the predecessor listin response to determining that the predecessor list is not empty.

In an aspect, the computing device may include means for determiningwhether the ready list is empty and means for selecting another node inthe ready list for optimization in response to determining that theready list is not empty. In another aspect, the computing device mayinclude means for determining whether all nodes in the graph have beenvisited in response to determining that the ready list is empty andmeans for adding an unvisited node to the ready list in response todetermining that all nodes in the graph have not been visited. In yetanother aspect, means for adding an unvisited node to the ready list mayinclude means for scanning the graph for unvisited nodes, means fordetermining whether a phi node in the graph has not been visited, meansfor selecting the phi node in response to determining that the phi nodehas not been visited, means for selecting another unvisited node inresponse to determining that there are no unvisited phi nodes, and meansfor adding the selected node to the ready list. In another aspect, meansfor adding an unvisited node to the ready list may include means forscanning the graph for unvisited nodes, means for sorting the unvisitednodes into a reverse postordering, means for selecting a first node inthe reverse postordering, and means for adding the selected node to theready list.

In further aspects, a non-transitory processor-readable storage mediummay have stored thereon processor-executable software instructionsconfigured to cause a processor to perform operations for optimizing anintermediate representation of source code, the operations includinggenerating a graph from the intermediate representation wherein thegraph includes a plurality of nodes, selecting a node in the graph,applying an optimization to the selected node, recognizing a boundedsubgraph based on the selected node, and propagating the optimization tonodes in the bounded subgraph. In another aspect, the storedprocessor-executable software instructions may be configured to cause aprocessor of a computing device to perform operations such thatrecognizing a bounded subgraph based on the selected node includesidentifying an entry node, wherein the entry node is a predecessor nodeof the selected node, scanning through the graph, determining whether anexit node is detected, wherein an exit node is a successor node of theselected node, and defining the bounded subgraph based on the entry nodeand the exit node in response to determining that an exit node isdetected. In another aspect, the stored processor-executable softwareinstructions may be configured to cause a processor of a computingdevice to perform operations that include determining whether there isan unvisited node in the graph and selecting an unvisited node foroptimization in response to determining that there is an unvisited nodein the graph.

In an aspect, the stored processor-executable software instructions maybe configured to cause a processor of a computing device to performoperations such that selecting a node in the graph includes initializinga ready list, adding a start node to the ready list, selecting a node inthe ready list, and incrementing a visitation counter of the selectednode. In another aspect, the stored processor-executable softwareinstructions may be configured to cause a processor of a computingdevice to perform operations such that selecting a node in the readylist includes determining whether there is a control flow node in theready list, selecting the control flow node in response to determiningthat a control flow node is in the ready list, and selecting a data nodein response to determining that there are no control flow nodes in theready list. In another aspect, the stored processor-executable softwareinstructions may be configured to cause a processor of a computingdevice to perform operations such that selecting a node in the readylist includes sorting nodes in the ready list into a reversepostordering, and selecting a first node in the reverse postordering.

In an aspect, the stored processor-executable software instructions maybe configured to cause a processor of a computing device to performoperations that include adding successors of the selected node to theready list, and removing the selected node from the ready list. Inanother aspect, the stored processor-executable software instructionsmay be configured to cause a processor of a computing device to performoperations such that adding successors of the selected node to the readylist includes, for each of the selected node's successors, determiningwhether predecessors of a successor node have all been visited, andadding the successor node to the ready list in response to determiningthat the successor node's predecessors have all been visited.

In an aspect, the stored processor-executable software instructions maybe configured to cause a processor of a computing device to performoperations such that applying an optimization to the selected nodeincludes determining whether the selected node has been visited morethan twice. In another aspect, the stored processor-executable softwareinstructions may be configured to cause a processor of a computingdevice to perform operations that include determining whether to apply aforwards optimization on the selected node in response to determiningthat the selected node has not been visited more than twice, applyingthe forwards optimization on the selected node in response todetermining to apply the forwards optimization on the selected node,determining whether to apply a backwards optimization on the selectednode in response to determining that the selected node has not beenvisited more than twice, and applying the backwards optimization on theselected node in response to determining to apply the backwardsoptimization. In another aspect, the stored processor-executablesoftware instructions may be configured to cause a processor of acomputing device to perform operations such that propagating theoptimization to nodes in the bounded subgraph includes propagating theforwards optimization through the bounded subgraph of the selected nodein response to determining to apply the forwards optimization on theselected node, and propagating the backwards optimization through thebounded subgraph of the selected node in response to determining toapply the backwards optimization on the selected node.

In an aspect, the stored processor-executable software instructions maybe configured to cause a processor of a computing device to performoperations such that propagating the forwards optimization through thebounded subgraph of the selected node includes initializing a successorlist, adding all successors of the selected node to the successor list,choosing a successor node from the successor list, incrementing avisitation counter of the chosen successor node, determining whether thechosen successor node has been visited more than twice, determiningwhether to apply the forwards optimization on the chosen successor nodein response to determining that the chosen successor node has not beenvisited twice, applying the forwards optimization on the chosensuccessor node in response to determining to apply the forwardsoptimization, determining whether the chosen successor node is an exitnode, adding successors of the chosen successor node to the successorlist unless it is determined that the chosen successor node is an exitnode or it is determined not to apply the forwards optimization on thechosen successor node, and removing the chosen successor node from thesuccessor list. In another aspect, the stored processor-executablesoftware instructions may be configured to cause a processor of acomputing device to perform operations that include determining whetherthe successor list is empty, and selecting another successor node in thesuccessor list in response to determining that the successor list is notempty.

In an aspect, the stored processor-executable software instructions maybe configured to cause a processor of a computing device to performoperations such that propagating the backwards optimization through thebounded subgraph of the selected node includes initializing apredecessor list, adding all predecessors of the selected node to thepredecessor list, choosing a predecessor node from the predecessor list,incrementing a visitation counter of the chosen predecessor node,determining whether the chosen predecessor node has been visited morethan twice, determining whether to apply the backwards optimization onthe chosen predecessor node in response to determining that the chosenpredecessor node has not been visited twice, applying the backwardsoptimization on the chosen predecessor node in response to determiningto apply the backwards optimization, determining whether the chosenpredecessor node is an entry node, adding a predecessor of the chosenpredecessor node to the predecessor list unless it is determined thatthe chosen predecessor node is an entry node or it is determined not toapply the backwards optimization on the chosen predecessor node, andremoving the chosen predecessor node from the predecessor list. Inanother aspect, the stored processor-executable software instructionsmay be configured to cause a processor of a computing device to performoperations that include determining whether the predecessor list isempty, and selecting another predecessor node in the predecessor list inresponse to determining that the predecessor list is not empty.

In an aspect, the stored processor-executable software instructions maybe configured to cause a processor of a computing device to performoperations that include determining whether the ready list is empty, andselecting another node in the ready list for optimization in response todetermining that the ready list is not empty. In another aspect, thestored processor-executable software instructions may be configured tocause a processor of a computing device to perform operations thatinclude determining whether all nodes in the graph have been visited inresponse to determining that the ready list is empty, and adding anunvisited node to the ready list in response to determining that allnodes in the graph have not been visited. In another aspect, the storedprocessor-executable software instructions may be configured to cause aprocessor of a computing device to perform operations such that addingan unvisited node to the ready list includes scanning the graph forunvisited nodes, determining whether a phi node in the graph has notbeen visited, selecting the phi node in response to determining that thephi node has not been visited, selecting another unvisited node inresponse to determining that there are no unvisited phi nodes, andadding the selected node to the ready list. In yet another aspect, thestored processor-executable software instructions may be configured tocause a processor of a computing device to perform operations such thatadding an unvisited node to the ready list includes scanning the graphfor unvisited nodes, sorting the unvisited nodes into a reversepostordering, selecting a first node in the reverse postordering, andadding the selected node to the ready list.

BRIEF DESCRIPTION OF THE DRAWINGS

The accompanying drawings, which are incorporated herein and constitutepart of this specification, illustrate exemplary aspects of theinvention, and together with the general description given above and thedetailed description given below, serve to explain the features of theinvention.

FIG. 1 is a system block diagram of a typical computing device suitablefor use with the various aspects.

FIG. 2 is a process flow diagram illustrating a typical method forcompiling source code.

FIG. 3 is a process flow diagram illustrating a typical method foroptimizing a graph generated from an intermediate representation ofsource code.

FIG. 4 is an illustration of a segment of code represented as a controlflow graph.

FIG. 5 is a process flow diagram illustrating an aspect method foroptimizing a graph generated from an intermediate representation ofsource code.

FIG. 6 is a process flow diagram illustrating an aspect method fordefining a bounded subgraph in relation to a node selected foroptimization.

FIG. 7 is a process flow diagram illustrating another aspect method foroptimizing a graph generated from an intermediate representation ofsource code.

FIGS. 8A-8B are process flow diagrams illustrating aspect methods forselecting a node in a ready-to-optimize list for optimization.

FIG. 9 is a process flow diagram illustrating an aspect method forpropagating a forwards optimization to a selected node's successors in abounded subgraph.

FIG. 10 is a process flow diagram illustrating an aspect method forpropagating a backwards optimization to a selected node's predecessorsin a bounded subgraph.

FIG. 11 is a process flow diagram illustrating an aspect method foradding a node's successors to the ready-to-optimize list.

FIGS. 12A-12B are process flow diagrams illustrating aspect methods foradding an unvisited node to the ready-to-optimize list when theready-to-optimize list is empty.

FIG. 13 is a block diagram of an example computing device according toan aspect.

FIG. 14 is a block diagram of another example computing device accordingto an aspect.

DETAILED DESCRIPTION

The various aspects will be described in detail with reference to theaccompanying drawings. Wherever possible, the same reference numberswill be used throughout the drawings to refer to the same or like parts.References made to particular examples and implementations are forillustrative purposes, and are not intended to limit the scope of theinvention or the claims.

The term “computing device” is used herein to refer to any one or all ofpersonal computers, servers, desktop computers, cellular telephones,smartphones, personal or mobile multi-media players, personal dataassistants (PDA's), laptop computers, tablet computers, smartbooks,palm-top computers, wireless electronic mail receivers, multimediaInternet enabled cellular telephones, wireless gaming controllers, andsimilar electronic devices that include a programmable processor and amemory. While the various aspects are particularly useful in mobilecomputing devices, such as cellular telephones, which have limitedprocessing power and battery capacity, the aspects are generally usefulin any computing device that may benefit from reduced compile times andreduced energy consumption.

As discussed above, current techniques for optimizing code includeperforming multiple, iterative passes over an intermediaterepresentation (IR) of the code to perform forwards and backwardsoptimizations. These techniques produce highly optimized code at thecost of increased compile time and shorter battery life. While the costsof performing contemporary optimization techniques may not greatlyaffect performance on computing devices that have higher processingpower and/or are not reliant on a battery (e.g., personal computers,desktops, servers, etc.), users of mobile computing devices thatimplement current optimization techniques may experience noticeablylonger application load times and shorter battery life. Thus, users maybenefit from an optimization strategy that minimizes the time andbattery power investment of performing code optimization whilemaximizing the benefits of code optimization.

In overview, the various aspects provide a dynamic compilation frameworkthat includes a machine-independent optimization module (e.g., amachine-independent optimizer implemented in software) operating on acomputing device and methods for optimizing code with themachine-independent optimization module using a single,combined-forwards-backwards pass of the code. In the various aspects,the machine-independent optimization module may generate a graph ofnodes (e.g., a directed, acyclic or cyclic graph) from the IR, optimizenodes in the graph using forwards and backwards optimizations, andpropagating the forwards and backwards optimizations to nodes in abounded subgraph recognized or defined based on the position of the nodecurrently being optimized. In the various aspects, themachine-independent optimization module may optimize the graph byperforming forwards and/or backwards optimizations during a single passthrough the graph, thereby achieving an effective degree of optimizationand shorter overall compile times. Thus, the various aspects may providea global optimization framework for dynamic compilers that is faster andmore efficient than existing solutions.

In an aspect, the machine-independent optimization module may optimizethe IR without knowing the characteristics of the final device on whichthe application program is deployed, and thus may perform the variousaspects as part of either the first or second stage of the two-partcompilation process.

In an aspect, the machine-independent optimization module may optimize agraph by performing a combination of forwards and backwardsoptimizations in a single pass of the graph. The machine-independentoptimization module may begin by optimizing a start node in the graphand traversing the graph in a forwards manner, applying one or moreforwards optimizations (e.g., sparse conditional constant propagation,global value numbering, etc.) and/or backwards optimizations to eachnode that may benefit from such optimizations. In another aspect, themachine-independent optimization module may utilize a“ready-to-optimize” list (i.e., a “ready list”), whereby themachine-independent optimization module may visit a node in the list(e.g., the start node), perform applicable forwards and/or backwardsoptimizations on the visited node, add the visited node's successors tothe ready list, remove the visited node from the ready list, and repeatthe process until the ready list is empty.

In another aspect, for each visited node, the machine-independentoptimization module may propagate applied forwards optimizations to thevisited node's successors and applied backwards optimizations to thevisited node's predecessors. The machine-independent optimization modulemay limit such propagations to nodes within a bounded subgraph aroundthe visited node. For instance, the machine-independent optimizationmodule may propagate a backwards optimization to the visited node'spredecessors until the machine-independent optimization module reachesan entry node (i.e., a “stopping” point in the beginning of a boundedsubgraph, such as a merge point or phi node). For example, themachine-independent optimization module may visit a node and perform adead code elimination (DCE) operation to remove that node from thegraph, move back up the bounded subgraph to that node's predecessor(s),determine whether the predecessor node(s) have any uses other thanfeeding information to the now-eliminated node, and if not, remove thepredecessor node(s) from the graph. Similarly, in another aspect, themachine-independent optimization module may also propagate a forwardsoptimization to the visited node's successor nodes until themachine-independent optimization module reaches an exit node (i.e., a“stopping” point at the end of the bounded subgraph).

The machine-independent optimization module may recognize the boundariesof a bounded subgraph in several ways. In an aspect, themachine-independent optimization module may dynamically (i.e., on thefly) recognize the boundaries of the subgraph during propagation offorwards and/or backwards optimizations. For example, themachine-independent optimization module may continue propagatingforwards and/or backwards propagations until the machine-independentoptimization module recognizes an entry or exit node (i.e., nodesrepresenting the boundary of the bounded subgraph). Thus, in such anaspect, the machine-independent optimization module may naturallyrecognize the boundaries of a visited node's subgraph as a consequenceof propagating the optimizations and not as a result of scanning throughthe graph beforehand.

In another aspect, the machine-independent optimization module maydefine or otherwise predetermine the boundaries of a bounded subgraphbefore propagating optimizations by scanning through the graph anddetermining one or more entry nodes and one or more exit nodes thatserve as natural start and end points for a particular visited node. Forexample, the machine-independent optimization module may select a groupof nodes that corresponds to a loop in the IR (e.g., a “for loop” or a“do-while” loop) to be a bounded subgraph. In a further aspect, thenodes comprising a bounded subgraph may be organized into a graph ortree structure so that the relationships between the nodes in thebounded subgraph (including the visited node) are clearly defined and sothat the bounded subgraph has at least one defined starting point and atleast one defined ending point.

In another aspect, the machine-independent optimization module may limitpropagation of forwards and/or backwards optimizations to nodes includedin a bounded subgraph to reduce or control the amount of informationstored in the cache or memory as part of the optimization process. In afurther aspect, by controlling the amount of information stored in thecache, the machine-independent optimization module may apply either aforward optimization or a backward optimization or both in a single passwithout substantial memory allocation or information storage overhead.

In another aspect, the machine-independent optimization module maymaintain a count of the total number of times each node in the graph hasbeen visited (i.e., optimized). For example, the machine-independentoptimization module may record that a node was visited once to receive aforwards optimization and was visited a second time during thepropagation of a backwards optimization. In such an aspect, themachine-independent optimization module may ensure that the nodes in thegraph are visited no more than two times. For example, a propagation ofa backwards optimization to a visited node's predecessors may cause themachine-independent optimization module to revisit a prior node. In thatevent, the machine-independent optimization module may apply thebackwards optimization to that node only if the node has not alreadybeen visited twice.

In the various aspects, the single-pass, forwards/backwards optimizationprocess may continue until all nodes in the graph are optimized,eliminated, or visited twice. By limiting the process tovisiting/optimizing nodes no more than two times, the various aspectsenable code optimization that is faster than existing iterativesolutions (i.e., exhibiting shorter compile times) while providing codeoptimizations that are on par with current iterative optimizationtechniques.

In further aspects, the machine-independent optimization module mayimplement various strategies for selecting the next node to process fromthe ready list. For example, the machine-independent optimization modulemay visit control-flow nodes in the ready list before visiting datanodes. In another example, the machine-independent optimization modulemay visit nodes in the ready list in reverse postorder.

In another aspect, the machine-independent optimization module may addnodes that have not yet been visited (i.e., “unvisited” nodes) to theready list when the ready list becomes empty. For example, themachine-independent optimization module may add a node to the ready listthat is unreachable from a start node. In a further aspect, themachine-independent optimization module may opt to add unvisited phinodes to the ready list first, followed by other types of unvisitednodes. In another aspect, the machine-independent optimization modulemay add unvisited nodes to the ready list based on a reversepostordering.

The various aspects may be implemented within a variety of computingdevices 100, an example block diagram of which is illustrated in FIG. 1.A computing device 100 may include an operating system 104, which may bea high-level operating system used to manage and execute varioussoftware 110 on the computing device 100. The operating system 104 mayalso enable various software 110 to access hardware resources 106, suchas memory 112 and a processor 114. The operating system 104 may host acompiler 108, which may be or may include a machine-independentoptimization module for optimizing intermediate representations of code.In another aspect, the compiler may be a module within a larger system.

The compiler may be one or more software programs that transforms sourcecode 102 written in one programming language (i.e., the source language)into another programming language (i.e., the target language). In anexample, the source code 102 may be a collection of computerinstructions typically written using a human-readable programminglanguage, such as Java®, C++, Perl®, Python®, etc., and the compiler 108may transform the source code 102 into an executable program. The sourcecode 102 may exist as one or more files or in a database and may bestored on various types of storage media (not shown), such as opticaldisks or hard-drive disks.

The compiler 108 may access the hardware resources 106 through theoperating system 104 to facilitate compiling the source code 102 into amore useful form. For example, the compiler 108 may have access to thememory 112 (e.g., RAM) and various registers (not shown) and may utilizethe processing capabilities of the processor 114.

FIG. 2 illustrates a typical method 200 that may be implemented in acompiler for compiling source code into executable code. In block 204,the compiler may obtain source code for compiling. For example, thecompiler may access source code stored on a hard drive included on thecomputing device. The compiler may also generate an intermediaterepresentation of the source code in block 206. For example, thecompiler may perform various operations to prepare the source code foroptimization, such as by checking the code for proper syntax andsemantics, parsing the source code, and building a corresponding parsetree and symbol table.

In block 208, the compiler may optimize the intermediate representation.The compiler may implement various optimization strategies. For example,the compiler may remove useless or unreachable code, discover andpropagate constant values, relocate computation to a less frequentlyexecuted place (e.g., moving an operation/instruction out of a loop), orspecializing a computation based on the context.

The compiler may also generate executable code from the optimizedintermediate representation in block 210. For example, the compiler mayconvert the optimized intermediate representation to machine code thatmay be executed by a processor on the computing device. The compiler mayalso output the executable code in block 212. For example, the compilermay output the executable code in the form of an executable applicationor program.

FIG. 3 illustrates a typical method 300 implemented by a typicalmachine-independent optimization module for optimizing a graph generatedfrom an intermediate representation of source code. The method 300implements operations of block 208 of method 200 described above withreference to FIG. 2. The machine-independent optimization module maystart performing method 300 after a compiler or another componentgenerates an intermediate representation of the source code in block 206of method 200 as described above with reference to FIG. 2.

In block 302, the machine-independent optimization module may typicallyreceive an intermediate representation (IR) of the source code foroptimization. In block 304, the machine-independent optimization modulemay generate a graph from the IR. The graph may include a plurality ofnodes that correspond to the IR of the source code, and themachine-independent optimization module may construct the graph usingknown methods.

In block 306, the machine-independent optimization module may optimizethe graph. In current implementations, a machine-independentoptimization module may start applying forwards optimizations beginningat the first node in the graph and will continue traversing the graphuntil the machine-independent optimization module reaches the end of thegraph. The machine-independent optimization module will then typicallystart applying backwards optimizations from the end of the graph throughpredecessor nodes until the machine-independent optimization modulereaches the beginning of the graph. Current methods may configure themachine-independent optimization module to continue applying forwardsand backwards passes, optimizing the code iteratively until someprocess-ending threshold is met indicating that the results of anotheriteration would be minimal. While applying multiple, iterative passesyields highly optimized code, such iterative methods increase compiletime and require considerably more power, which may impact the batterylife of many mobile device.

Typically after optimizing the graph, the machine-independentoptimization module may generate machine code from the optimizedintermediate representation in block 210 of method 200 described withreference to FIG. 2.

FIG. 4 illustrates example source code and a graph generated from an IRof the source code. In the example, the source code 422 (illustrated inFIG. 4 as a high-level, human-readable pseudo code) includes variousoperations, including a set of instructions for performing a do-whilelooping operation (i.e., the code segment 426). In such an example, thecode segment 426 may set a variable “x” to zero in an assignmentoperation 428 (i.e., “x=0;”). The code segment 426 may also includeinstructions that increment the value of the variable (i.e., the “doinstruction” 430) and perform a check to determine whether the value ofthe variable is greater than ten (i.e., the “while instruction” 432).These operations may continue in a loop, such that the variable's valuemay continue to be incremented until the variable's value is equal toten.

As discussed above with reference to FIG. 3, a compiler operating on thecomputing device may produce an IR 440 of the source code 422, and themachine-independent optimization module may generate a graph 402 fromthe IR 440. For example, the first node in the graph 402 (i.e., node406) may correspond to the IR of the beginning of the source code 424,and the last node in the graph 402 (i.e., node 420) may correspond tothe IR of the end of the source code 434. In an aspect, there may be oneor more intermediary nodes of varying types in between node 406 and node420, and these intermediary nodes may represent the various operationsincluded in the IR 440 of the source code 422.

In an aspect, the machine-independent optimization module may generatethe graph 402 in static single assignment (“SSA”) form, which requireseach variable to be assigned exactly once such that each definition of avariable has its own variable or “definition.” For example, thestatement “x=x+1” may be represented as “x₂=x₁+1,” wherein each versionof “x” is treated as a separate variable. In another aspect, the nodesin the graph may include representations of one or more operations inthe IR 440.

In the example illustrated in FIG. 4, a portion of the graph 404 maycorrespond to the IR of the code segment 426. In this example, theportion of the graph 404 may include various nodes related to thedo-while loop structure in the code segment 426. For instance, theportion of the graph 404 may begin at data node 410, which may bereachable from a prior node in the graph 402.

At data node 410, a data operation may be performed (i.e., the SSAvariable “x₁” is assigned a value of zero). The operational flow mayflow to phi node 412. In an aspect, because putting an IR into SSA formmay create multiple versions of a single variable, phi nodes mayfunction as a merge point in which one of multiple versions of avariable is selected for further computation. In phi node 412, a versionof “x” may be selected based on the control flow (i.e., “x₂=Φ(x₁, x₃)).For example, “x₁” may be selected at phi node 412 when control hasflowed from data node 410, but “x₃” may be selected when control flowsfrom the control flow node 416.

The control may flow from phi node 412 to data node 414. In data node414, the “x₃” variable may be assigned the sum of “x₂” plus one, whichmay correspond to the do instruction 430 in the code segment 426.Operations may continue in control flow node 416, wherein the value ofthe variable “x₃” is checked. Control may flow to phi node 412 when “x₃”is less than 10, or control may continue to flow towards the end node420 in the graph 402 when “x₃” is ten.

In various aspects, the machine-independent optimization module mayoptimize a graph through a single pass from a start node (e.g., startnode 406) to an end node (e.g., end node 420) and may apply bothforwards and backwards optimizations to the nodes (i.e., visited nodes)in the graph during the single pass. For example, after visiting datanode 410 and applying forwards optimization, the machine-independentoptimization module may visit phi node 412 (i.e., a successor of thedata node 410) and determine whether the phi node 412 would benefit fromforwards optimizations.

In another aspect, the machine-independent optimization module may applyforwards and/or backwards optimizations on nodes a maximum of two times.The process of applying optimizations during a the single pass of eachgraph is described in further detail with reference to FIGS. 5 and 7.

In further aspects, the machine-independent optimization module maypropagate optimizations applied to a visited node to other nodesincluded in a bounded subgraph recognized or defined in relation to thevisited node. A bounded subgraph may include one or more entry nodes(i.e., one or more starting points), one or more exit nodes (i.e., oneor more stopping points), and one or more intermediary nodes. The nodesin the bounded subgraph may include the following node types: controlflow nodes (e.g., representing loops and other constructs that determinewhat operations are to be performed next); data nodes (e.g., operationssuch as addition, subtraction, etc.); and “phi nodes,” which are mergepoints in the code that identify a relationship between the differentpaths between the control flow nodes and the data nodes.

In an aspect, the machine-independent optimization module maydynamically (i.e., on the fly) recognize the boundaries of a boundedsubgraph during propagation of optimizations to a visited node'ssuccessors and/or predecessors by traversing backwards from the visitednode until one or more “entry” nodes (e.g., a phi node or anotherstarting point) are detected and by traversing forwards from the visitednode until one or more “exit” nodes (e.g., a phi node or anotherstopping point) are detected.

In another aspect, for each visited node, the machine-independentoptimization module may break the graph 402 into a predetermined,defined bounded subgraph before propagating optimizations from thevisited node. The process of breaking the graph into bounded subgraphsis described in further detail below with reference to FIG. 6.

In another aspect, the machine-independent optimization module maydefine or recognize bounded subgraphs around structures in the code thatmay have a clear start and end, such as loops, conditional statements,etc. Also, because bounded subgraphs are recognized or defined inrelation to separate visited nodes, each visited node may have adifferent bounded subgraph associated with it.

Returning to FIG. 4, the machine-independent optimization module mayvisit the data node 414 and determine that the data node 414's boundedsubgraph 404 starts at phi node 412 (i.e., an entry node) and stops atcontrol flow node 416 (i.e., an exit node). After applying a backwardsoptimization to the data node 414, the machine-independent optimizationmodule may begin propagating the backwards optimization to the data node414's predecessors (e.g., phi node 412). The machine-independentoptimization module may then determine whether the phi node 412 maybenefit from a backwards optimization and apply the backwardsoptimization if applicable. The machine-independent optimization modulemay end the backwards traversal at this point because themachine-independent optimization module may recognize the phi node 412as the beginning of the bounded subgraph (i.e., a stopping point).

In another example, the machine-independent optimization module mayapply a forwards optimization to data node 414 and may propagate theforwards optimization to the data node 414's successors (e.g., controlflow node 416), which the machine-independent optimization module mayrecognize as the end of the bounded subgraph.

FIG. 5 illustrates an aspect method 500 that may be implemented by amachine-independent optimization module for optimizing a graph generatedfrom an IR of source code. In various aspects, the machine independentoptimization module may determine the optimization that is the best foreach node in the graph and may apply that optimization on the node. Infurther aspects, the machine-independent optimization module maypropagate the node's optimizations to other nodes within the node'sbounded subgraph.

In an aspect, the operations of method 500 may represent an overviewmethod for optimizing a graph. As such, the operations of method 500implement an aspect of the operations of block 306 of method 300described above with reference to FIG. 3. The machine-independentoptimization module may begin performing method 500 after generating agraph from an IR of the source code in block 304 of method 300 asdescribed with reference to FIG. 3.

In block 502, the machine-independent optimization module may select anode in the graph. In an aspect, the machine-independent optimizationmodule may first select a node at the beginning of the graph (i.e., astarting node).

In block 504, the machine-independent optimization module may applyoptimizations to the selected node. In an aspect, themachine-independent optimization module may determine to apply one ormore forwards and/or backwards optimizations to the selected node. Forexample, the machine-independent optimization module may determine toapply a backwards optimization to the selected node (e.g., dead codeelimination) and may remove the node from the graph as a result.

In block 506, the machine-independent optimization module may recognizea bounded subgraph based on the selected node. In an aspect, themachine-independent optimization module may define a portion of thegraph around the selected node to be the selected node's boundedsubgraph. In an aspect, the bounded subgraph may be well defined suchthat the bounded subgraph includes one or more entry nodes that mark thebeginning of the bounded subgraph and one or more exit nodes that markthe end of the bounded subgraph. In a further aspect, the one or moreentry and exit nodes may be particular types of nodes, such asmerge-point nodes, phi nodes, start nodes, end nodes, and other specialcase nodes. In another aspect, the entry and exit nodes may be definedaround natural sections of the code represented by the graph. In otherwords, the entry and exit nodes may correspond to the beginning and endof a loop instruction, conditional statement, or other discrete segmentof code. The process of defining a bounded subgraph based on a selectednode is described in further detail below with reference to FIG. 6.

In another aspect, the machine-independent optimization module mayrecognize the selected node's bounded subgraph dynamically during theprocess of propagating the optimizations to the selected node'spredecessors and/or successors as described with reference to block 508.In other words, the machine-independent optimization module mayrecognize the natural boundaries (i.e., entry and exit nodes) of theselected node's subgraph without predetermining those boundaries beforepropagating optimizations from the selected node.

In block 508, the machine-independent optimization module may propagatethe optimizations to the nodes in the bounded subgraph. In an aspect,when the machine-independent optimization module determines to apply aforwards optimization to the selected node, the machine-independentoptimization module may propagate the forwards optimizations to theselected node's successor nodes until the end of the bounded subgraph isreached (i.e., until one or more exit nodes are reached). In anotheraspect, when the machine-independent optimization module determines toapply a backwards optimization to the selected node, themachine-independent optimization module may propagate the backwardsoptimization to the selected node's predecessors within the defined orrecognized bounded subgraph. Optimizations are only propagated to nodeswithin the selected node's bounded subgraph, thus reducing the amount ofinformation that must be stored in the cache as part of the optimizationoperations in comparison to propagating the optimizations throughout theentire graph. As described above, the machine-independent optimizationmodule may recognize the boundaries of the bounded subgraph dynamicallyduring propagation of the optimizations or as a result of apredetermination of the boundaries of the subgraph.

In determination block 510, the machine-independent optimization modulemay determine whether there is an unvisited node in the graph. In otherwords, the machine-independent optimization module may determine whetherit has attempted to optimize each node in the graph. In an aspect, themachine-independent optimization module may optimize the graph one nodeat a time until the entire graph is optimized. In another aspect, duringoptimization of the graph, the machine-independent optimization modulemay visit each node a maximum of two times. For example, a node may beselected and have a forwards optimization applied to it (i.e., a firstvisit), and the node may later have a propagated backwards optimizationapplied to it (i.e., a second visit). In such an example, themachine-independent optimization module may not visit the node again,and no additional optimizations may be applied to the node.

When the machine-independent optimization module determines that thereis an unvisited node in the graph left to optimize (i.e., determinationblock 510=“Yes”), the machine-independent optimization module may selectan unvisited node in the graph for optimization in block 512. In anaspect, the machine-independent optimization module may select a node inthe graph in block 512 in a manner similar to how themachine-independent optimization module selects a node in the graph inblock 502 as described above. In an aspect, the process may continue ina loop as the machine-independent optimization module may continueapplying optimizations to selected nodes in the graph in block 504 untilthe entire graph is optimized.

When the machine-independent optimization module determines that thereis no unvisited node in the graph (i.e., determination block 510=“No”),the compiler may create machine code from the optimized IR generatedfrom the machine-independent optimization module's optimization of thegraph in block 210 of method 200 as described above with reference toFIG. 2.

FIG. 6 illustrates an aspect method 600 that may be implemented by amachine-independent optimization module for defining a bounded subgraphbased on a currently selected node. The operations of method 600implement an aspect of the operations of block 506 of method 500described above with reference to FIG. 5. The machine-independentoptimization module may begin performing method 600 after applyingoptimizations to a selected node in block 504 of method 500 as describedwith reference to FIG. 5.

In block 602, the machine-independent optimization module may identifyone or more entry nodes. For example, the machine-independentoptimization module may traverse the graph backwards from the selectednode until it discovers an entry node. In an aspect, an entry node maybe a node that corresponds with a logical starting point in the IR orsource code. For example, the one or more entry nodes may be thebeginning of a looping or conditional segment of code. In anotheraspect, the one or more entry nodes may be phi nodes or some other“merge” points in which there may be no ambiguity in the value of avariable. In another aspect, the one or more entry nodes may also beon-stack replacement nodes, which may be the beginning of a portion ofthe graph that represents an inlined function.

In block 604, the machine-independent optimization module may scanthrough the graph. For example, the machine-independent optimizationmodule may conduct a forward traversal of the graph beginning with theone or more entry nodes' immediate successors and continuing through theone or more entry nodes' more distant descendents. In determinationblock 606, the machine-independent optimization module may determinewhether one or more exit nodes are detected. In an aspect, an exit nodemay be a logical end point in the IR or source code. In the examplesprovided above, a logical exit node may correspond to the end of alooping or conditional segment of code. In another aspect, exit nodesmay be program exit nodes (e.g., normal exits, exception exits, etc.).In another aspect, exit nodes may represent safe-points in the programused, for example, for garbage collection.

When the machine-independent optimization module determines that one ormore exit nodes are not detected (i.e., determination block 606=“No”),the machine-independent optimization module may continue scanningthrough the graph in block 608. This process may continue in a loopuntil the machine-independent optimization module determines that one ormore exit nodes are detected.

When the machine-independent optimization module determines that one ormore exit nodes are detected (i.e., determination block 606=“Yes”), themachine-independent optimization module may define the bounded subgraphbased on the one or more entry nodes and the one or more exit node inblock 610. In other words, the bounded subgraph may include the one ormore entry nodes, the one or more exit nodes, and intermediary nodesbetween the entry and exit nodes (e.g., the selected node).

The machine-independent optimization module may continue with theoperations in method 500 by propagating the optimizations to nodes inthe selected node's bounded subgraph in block 508 of method 500described above with reference to FIG. 5.

In further aspects, because a bounded subgraph is defined or naturallyrecognized based on the location of the currently selected node, themachine-independent optimization module may encounter a differentbounded subgraph for each selected node. In other words, as themachine-independent optimization module propagates optimizations from aselected node during a single pass of the graph, the nodes affected bythe propagated optimizations may be limited to the nodes included ineach selected node's particular bounded subgraph.

FIG. 7 illustrates an aspect method 700 that may be implemented by amachine-independent optimization module for optimizing a graph generatedfrom the IR of the source code in a single pass. The operations ofmethod 700 implement an aspect of the operations of method 500 describedabove with reference to FIG. 5. Accordingly, the machine-independentoptimization module may begin performing method 700 after generating agraph from an IR of the source code in block 304 of method 300 asdescribed with reference to FIG. 3.

In block 702, the machine-independent optimization module may initializea “ready to optimize list” (i.e., a “ready list”). In an aspect, theready list may include nodes in the graph that are ready for themachine-independent optimization module to optimize. In another aspect,a node may be “ready” for optimization when the machine-independentoptimization module has already visited/optimized the node'spredecessors.

In block 704, the machine-independent optimization module may add one ormore start nodes to the ready list. In an aspect, a start node may be afirst node in the graph. In a further aspect, one or more start nodesmay be added to the ready list because, as the first nodes, they have nopredecessor nodes.

In block 706, the machine-independent optimization module may select anode in the ready list. In an aspect, the machine-independentoptimization module may implement various strategies for selecting thenode in the ready list that is selected. For example, themachine-independent optimization module may always attempt to select acontrol flow node first and may select other nodes only after selectingall available control flow nodes. Selecting a node from the ready listis discussed in further detail below with reference to FIGS. 8A and 8B.

In block 710, the machine-independent optimization module may incrementthe selected node's visitation counter. In an aspect, themachine-independent optimization module may maintain a count of thenumber of times each node has been visited. For example, themachine-independent optimization module may maintain a visitationcounter for each node that is stored in memory. In another aspect, themachine-independent optimization module may reference each node'svisitation counter before visiting the node to ensure that no node inthe graph is visited more than twice. In another aspect, rather than acounter, the machine-independent optimization module may utilize othermechanisms to identify when a node is no longer eligible for furtheroptimizations, such as by setting a flag to “finished” to indicate whenthe node has already been visited twice or by utilizing lists or tables.

In determination block 712, the machine-independent optimization modulemay determine whether the selected node has been visited more thantwice. In an aspect, the machine-independent optimization module mayvisit each node in the graph a maximum of two times while performing thesingle pass of the graph. By limiting the number of times each node maybe optimized (i.e., visited), the machine-independent optimizationmodule ensures a reasonable optimization/compile time withoutcompromising the quality of the optimizations made on the code.

When the machine-independent optimization module determines that theselected node has been visited more than twice (i.e., determinationblock 712=“Yes”), the machine-independent optimization module maycontinue performing method 700 in block 728 by adding successors of theselected node to the ready list as described below. In other words, themachine-independent optimization module may determine that a node thathas been already been visited twice may be ineligible for furtheroptimization and may skip over that node.

On the other hand, when the machine-independent optimization moduledetermines that the selected node has not been visited more than twice(i.e., determination block 712=“No”), the machine-independentoptimization module may recognize a bounded subgraph for the selectednode in block 714. In an aspect, the machine-independent optimizationmodule may predetermine the boundaries of a bounded subgraph for theselected node by performing the operations of method 600 described withreference to FIG. 6. In other words, the machine-independentoptimization module may identify one or more entry nodes and one or moreexit nodes based on the position of the selected node and predeterminethat the bounded subgraph includes the one or more entry nodes, the oneor more exit nodes, and intermediary nodes (including the selected node)between the entry and exit nodes. In another aspect, themachine-independent optimization may naturally discover the boundariesof the selected node's subgraph during propagation of forwards and/orbackwards optimizations without predetermining the bounded subgraph'sboundaries.

In determination block 716, the machine-independent optimization modulemay determine whether to apply one or more forwards optimizations to theselected node. For example, the machine-independent optimization modulemay determine whether the selected node is eligible or would benefitfrom any combination of several forwards optimizations, such as sparseconditional constant propagation or global value numberingoptimizations. When the machine-independent optimization moduledetermines not to apply forwards optimization to the selected node(i.e., determination block 716=“No”), the machine-independentoptimization module may continue performing by determining whether toapply backwards optimization to the selected node in determination block722.

When the machine-independent optimization module determines to applyforwards optimization to the selected node (i.e., determination block716=“Yes”), the machine-independent optimization module may apply theforwards optimization to the selected node in block 718. For example,the machine-independent optimization module may apply global valuenumbering to the selected node, which may assign the same value numberto variables and expressions that are provably equivalent. In anotheraspect, the machine-independent optimization module may carry forwardprevious forwards optimizations to the currently selected node.

In block 720, the machine-independent optimization module may propagatethe forwards optimization through the selected node's bounded subgroup.In an aspect, the machine-independent optimization module may attempt topropagate the forwards optimization to the selected node's successorsand stop when the boundary of the bounded subgraph is reached (i.e.,stop after propagating the forwards optimizations to the one or moreexit nodes). The process of propagating the forwards optimizationthrough the bounded subgraph is further described below with referenceto FIG. 9.

In determination block 722, the machine-independent optimization modulemay determine whether to apply backwards optimization to the selectednode. For example, the machine-independent optimization module maydetermine whether the selected node includes dead or unreachable code(i.e., a “dead code elimination” optimization). When themachine-independent optimization module determines not to applybackwards optimizations to the selected node (i.e., determination block722=“No”), the machine-independent optimization module may continueperforming method 700 by adding successors of the selected node to theready list in block 728.

When the machine-independent optimization module determines that itshould apply backwards optimization on the selected node (i.e.,determination block 722=“Yes”), the machine-independent optimizationmodule may apply a backwards optimization to the selected node in block724. If the machine-independent optimization module determines that theselected node includes only dead or unreachable code it may remove theselected node to simplify/optimize the overall graph. Once a node isremoved from the graph, the machine-independent optimization module maynot visit the node again and may update the node's predecessors andsuccessors to reflect the node's removal.

In block 726, the machine-independent optimization module may propagatethe backwards optimization through the selected node's bounded subgraph.The machine-independent optimization module may propagate the backwardsoptimizations because the machine-independent optimization moduleprocesses each node dynamically (i.e., “on-the-fly”). Thus, afterprocessing a later node, the machine-independent optimization module mayneed to propagate the optimizations backwards to determine if theoptimizations of the currently selected node open up additionaloptimizations in the currently selected node's predecessors. Forexample, if the machine-independent optimization module determines thatthe selected node only includes dead code (e.g., by applying dead codeelimination optimization) it may remove the selected node from thegraph. In this example, the machine-independent optimization module maytrace the selected node's predecessors to determine whether to applybackwards optimizations on the predecessors given the selected node'sremoval from the graph. In other words, the machine-independentoptimization module may determine whether the predecessor nodes shouldremain in the graph once the selected node has been removed from thegraph.

In block 728, the machine-independent optimization module may add theselected node's successors to the ready list. In an aspect, themachine-independent optimization module may add a successor node to theready list when all of the successor node's predecessors have beenvisited/processed. In another aspect, by only adding successor nodes tothe ready list, the machine-independent optimization module may ensurethat a node's first visit is not during the propagation of a backwardsoptimization.

In block 730, the machine-independent optimization module may remove theselected node from the ready list. While the selected node is removedfrom the ready list, the selected node may be visited for a second timeduring the propagation of backwards optimizations from one of theselected node's successor nodes.

In determination block 732, the machine-independent optimization modulemay determine whether the ready list is empty. In an aspect, the readylist may periodically become empty for various reasons. For example, anode may have a predecessor that has not been processed (e.g., thepredecessor node is not reachable from a start node). When themachine-independent optimization module determines that the ready listis not empty (i.e., determination block 732=“No”), themachine-independent optimization module may select another node in theready list for optimization in block 708. In an aspect, themachine-independent optimization module may select another node in block708 in a manner similar to the one described above with reference toblock 706. The process may continue in a loop as the machine-independentoptimization module may continue to select other nodes in the ready listin block 708 until the ready list is empty.

When the machine-independent optimization module determines that theready list is empty (i.e., determination block 732=“Yes”), themachine-independent optimization module may determine whether all nodesin the graph have been visited in determination block 736. In an aspect,some nodes may be unreachable from the start node and thus may not havebeen visited because they are not descendents of the start node.

When the machine-independent optimization module determines that allnodes have not been visited (i.e., determination block 736=“No”), themachine-independent optimization module may add an unvisited node to theready list in block 734. For example, the machine-independentoptimization module may add a node that is unreachable from the startnode to the ready list. In an aspect, this process may continue in aloop as the machine-independent optimization module may continueperforming method 700 until all nodes in the graph are optimized,eliminated, or visited twice.

When the machine-independent optimization module determines that allnodes have been visited (i.e., determination block 736=“Yes”), thecompiler may generate machine code from the optimized intermediaterepresentation in block 210 of method 200 described above with referenceto FIG. 2. In other words, the machine-independent optimization modulemay have completed the single-pass optimization of the graph when allnodes have been optimized/visited, and the compiler may continue byturning the optimized graph into machine code.

FIGS. 8A and 8B illustrate aspect methods 800, 820 that may beimplemented by a machine-independent optimization module for selecting anode in the ready list. These aspect methods may have differentcompilation speeds and other performance trade-offs.

The operations of methods 800, 820 implement aspects of the operationsof block 706 of method 700 described above with reference to FIG. 7. Invarious aspects, the machine-independent optimization module mayimplement a priority or sorting technique to select nodes in the readylist. The machine-independent optimization module may begin performingmethods 800, 820 after adding the start node to the ready list in block704 of method 700 described above with reference to FIG. 7.

FIG. 8A illustrates an aspect method 800 for selecting a node in theready list based on the type of node. In determination block 802, themachine-independent optimization module may determine whether there is acontrol flow node in the ready list. A control flow node may be a nodethat controls the flow of operations, such as loops, conditionalstatements, and function calls. In an aspect, the machine-independentoptimization module may give a higher priority to control flow nodesthan other types of nodes.

When the machine-independent optimization module determines that thereis a control flow node in the ready list (i.e., determination block802=“Yes”), the machine-independent optimization module may select acontrol flow node in block 804. While not illustrated, in anotheraspect, the machine-independent optimization module may apply a furthersorting criterion to determine the particular control flow node that isselected when there is more than one control flow node in the readylist. For example, the machine-independent optimization module mayselect the control flow node that is closest to the start node, or themachine-independent optimization module may select the control flow nodethat was added to the ready list first. The machine-independentoptimization module may continue with the operations in method 700 byincrementing the selected node's visitation counter in block 710 asdescribed with reference to FIG. 7.

When the machine-independent optimization module determines that thereare no control flow nodes in the ready list (i.e., determination block802=“No”), the machine-independent optimization module may select a datanode in block 806. In an aspect, a flow node may be a node correspondingwith various data manipulations, such as addition, subtraction,assignment, etc. In another aspect, the machine-independent optimizationmodule may employ secondary sorting criteria to select the data nodewhen more than one data node is in the ready list. Themachine-independent optimization module may continue with the operationsin method 700 by incrementing the selected node's visitation counter inblock 710 as described with reference to FIG. 7.

FIG. 8B illustrates an aspect method 820 for selecting a node in theready list based on a reverse postordering of the nodes. In block 822,the machine-independent optimization module may sort the nodes in theready list in reverse postorder. In an aspect, the machine-independentoptimization module may sort the nodes in reverse postorder by orderingthe nodes in the order they were last visited (i.e., a postordering) andreversing that ordering. In another aspect, implementing a reversepostordering of the nodes in the ready list may be useful as reversepostordering produces a topological sorting of graphs (e.g., directedacyclic graphs and cyclical graphs) and often represents a naturallinearization of control flow. In block 824, the machine-independentoptimization module may select the first node in the reversepostordering.

The machine-independent optimization module may continue with theoperations in method 700 by incrementing the selected node's visitationcounter in block 710 as described with reference to FIG. 7.

While not illustrated in FIGS. 8A and 8B, in another aspect, it isanticipated that the machine-independent optimization module may performoperations similar to those described with reference to methods 800, 820when selecting another node in the ready list in block 708 of method 700described above with reference to FIG. 7. In such an aspect, themachine-independent optimization module may perform methods 800, 820 oroperations analogous to those described with reference to methods 800,820 after determining that the ready list is not empty (i.e.,determination block 732=“No”) or after adding an unvisited node to theready list in block 734 of method 700 described above with reference toFIG. 7.

FIG. 9 illustrates an aspect method 900 that may be implemented by amachine-independent optimization module for propagating forwardsoptimizations to a selected node's successors within the selected node'sbounded subgraph. The operations of method 900 implement an aspect ofthe operations of block 720 of method 700 described above with referenceto FIG. 7. The machine-independent optimization module may beginperforming method 900 after applying one or more forwards optimizationsto the selected node in block 718 of method 700 described above withreference to FIG. 7.

In block 902, the machine-independent optimization module may initializea list of successor nodes (i.e., the “successor list”). In an aspect,the machine-independent optimization module may use the successor listin a manner similar to the ready list. In other words, themachine-independent optimization module may add successor nodes to thelist, process those successor nodes, and remove them from the list afterprocessing.

In block 904, the machine-independent optimization module may add theselected node's successors to the successor list. In block 906, themachine-independent optimization module may choose a successor node fromthe successor list. In an aspect, the machine-independent optimizationmodule may implement various sorting strategies and select a successornode based on its order. For example, the machine-independentoptimization module may sort the nodes by type and select control nodesfirst.

In block 910, the machine-independent optimization module may incrementthe chosen successor node's visitation counter. In determination block912, the machine-independent optimization module may determine whetherthe chosen successor node has been visited more than twice. In anaspect, the chosen successor node may have previously been visited undervarious circumstances. For example, the chosen successor node may havebeen selected/visited as described with reference to FIG. 7. In anotherexample, the machine-independent optimization module may have visitedthe chosen successor node during one or more optimization propagationsfrom other selected nodes. For instance, the chosen successor node mayhave been visited a first time during a forwards propagation from afirst selected node and visited a second time during a subsequentforwards propagation from a second selected node. In other words, thenode may have been included in more than one bounded subgraph fordifferent selected nodes and may have been visited during multipleoptimization propagations.

In an aspect, the machine-independent optimization module may notvisit/optimize a node more than two times during the single pass of thegraph, and the machine-independent optimization module may check thechosen successor node's visitation counter to ensure that the chosensuccessor node is eligible for further optimization. For example, themachine-independent optimization module may revisit a successor node forwhich it has previously performed a forwards optimization, meaning thatthe node has now been visited twice, and the machine-independentoptimization module may indicate that the node is now ineligible forfurther optimization.

In another aspect (not shown), the machine-independent optimizationmodule may determine whether the chosen successor node has been visitedtwice by checking that the chosen successor node's flag is set to“finished,” which may indicate that the chosen successor node has beenvisited twice and that the chosen successor node is ineligible forfurther optimizations. In another aspect, the machine-independentoptimization module may utilize various other methods of tracking thenumber of times each node in the graph has been visited (e.g., tables,lists, etc.).

When the machine-independent optimization module determines that thechosen successor node has been visited more than twice (i.e.,determination block 912=“Yes”), the machine-independent optimizationmodule may continue performing method 900 by determining whether thechosen successor node is an exit node in determination block 922.

When the machine-independent optimization module determines that thechosen successor node has not been visited more than twice (i.e.,determination block 912=“No”), the machine-independent optimizationmodule may determine whether to apply forwards optimizations to thechosen successor node in determination block 918.

In an aspect, the machine-independent optimization module may determinewhether to apply forwards optimizations on the chosen successor nodebased on criteria similar to the ones the machine-independentoptimization module relies on when determining whether to apply forwardsoptimizations on the selected node in determination block 716 of method700 described above with reference to FIG. 7.

When the machine-independent optimization module determines not to applyforwards optimizations on the chosen successor node (i.e., determinationblock 918=“No”), the machine-independent optimization module may removethe chosen successor node from the successor list in block 926. In anaspect, the machine-independent optimization module may not propagateforwards optimization to the successors of a chosen successor node inresponse to determining not to apply forwards optimizations on thechosen successor node.

When the machine-independent optimization module determines that itshould apply forwards optimizations on the chosen successor node (i.e.,determination block 918=“Yes”), the machine-independent optimizationmodule may apply forwards optimizations for the chosen successor node inblock 920.

In determination block 922, the machine-independent optimization modulemay determine whether the chosen successor node is an exit node. Asdiscussed above, an exit node may indicate the outer most boundary ofthe selected node's bounded subgraph. In other words, the exit node mayindicate a well-defined stopping point in the propagation of forwardsoptimizations. In an aspect, an exit node may be an end node, a phinode, or another node that indicates a logical stopping point inforwards propagation (e.g., a node that corresponds to the end of aconditional statement in the source code). In a further aspect, abounded subgraph may include one or more exit nodes. Thus, themachine-independent optimization module may not propagate the forwardsoptimizations further than an exit node. In a further aspect, themachine-independent optimization module may recognize that a node is anexit node dynamically (i.e., on the fly) or as a result ofpredetermining the boundaries of the selected node's bounded subgraph.

When the machine-independent optimization module determines that thechosen successor node is an exit node (i.e., determination block922=“Yes”), the machine-independent optimization module may remove thechosen successor node from the successor list in block 926. In anaspect, because the exit node indicates a stopping point in propagationof forwards optimizations, the machine-independent optimization modulemay not propagate the forwards optimizations to the chosen successornode's successors.

On the other hand, when the machine-independent optimization moduledetermines that the chosen successor node is not an exit node (i.e.,determination block 922=“No”), the machine-independent optimizationmodule may add the chosen successor node's successors to the successorlist in block 924. In other words, the machine-independent optimizationmodule may continue propagating the forwards optimizations to the chosensuccessor node's successors. The machine-independent optimization modulemay also remove the chosen successor node from the successor list inblock 926.

In determination block 928, the machine-independent optimization modulemay determine whether the successor list is empty. In other words, themachine-independent optimization module may determine whether it hasfinished propagating forwards optimizations through the selected node'sbounded subgraph. When the machine-independent optimization moduledetermines that the successor list is not empty (i.e., determinationblock 928=“No”), the process may continue in a loop as themachine-independent optimization module may choose another successornode in the successor list in block 908 and perform the operationsdescribed above until the successor list is empty.

When the machine-independent optimization module determines that thesuccessor list is empty (i.e., determination block 928=“Yes”), themachine-independent optimization module may continue performing in blockdetermination block 722 of method 700 described above with reference toFIG. 7 by determining whether to apply backwards optimizations to theselected node.

FIG. 10 illustrates an aspect method 1000 that may be implemented by amachine-independent optimization module for propagating backwardsoptimizations to a selected node's predecessors included in the selectednode's bounded subgraph. The operations of method 900 implement anaspect of the operations of block 726 of method 700 described above withreference to FIG. 7. The machine-independent optimization module maybegin performing method 1000 after applying one or more backwardsoptimizations to the selected node in block 724 of method 700 describedabove with reference to FIG. 7.

In block 1002, the machine-independent optimization module mayinitialize a list of predecessor nodes (i.e., the “predecessor list”).In an aspect, the machine-independent optimization module may use thepredecessor list in a manner similar to the ready list or successorlists described above. The machine-independent optimization module mayadd predecessor nodes to the list, process those predecessor nodes, andremove them from the list after processing.

In block 1004, the machine-independent optimization module may add theselected node's predecessors to the predecessor list. In block 1006, themachine-independent optimization module may choose a predecessor nodefrom the predecessor list. In an aspect, the machine-independentoptimization module may implement various sorting strategies and selecta predecessor node based on its order. For example, themachine-independent optimization module may sort the nodes by type andselect control nodes first.

In determination block 1010, the machine-independent optimization modulemay increment the chosen predecessor node's visitation counter. Indetermination block 1012, the machine-independent optimization modulemay determine whether the chosen predecessor node has been visited morethan twice. In an aspect, the chosen predecessor node may havepreviously been visited under various circumstances as described abovewith reference to determination block 912 of method 900 described withreference to FIG. 9. In an aspect, the machine-independent optimizationmodule may not visit/optimize a node more than two times as describedabove.

When the machine-independent optimization module determines that thechosen predecessor node has been visited more than twice (i.e.,determination block 1012=“Yes”), the machine-independent optimizationmodule may determine whether the chosen predecessor node is an entrynode in determination block 1022. In an aspect, an entry node mayrepresent the beginning of a selected node's bounded subgraph and mayindicate the stopping point for backwards propagation of backwardsoptimizations. In other words, similar to how the machine-independentoptimization module may stop propagating forwards optimizations onreaching an exit node as described above with reference to FIG. 9, themachine-independent optimization module may not propagate backwardsoptimizations to the predecessors of an entry node. Thus, as withforwards optimizations, the machine-independent optimization module mayonly propagate backwards optimizations to nodes included in the selectednode's bounded subgraph. As also described above, in a further aspect,the machine-independent optimization module may recognize that a node isan entry node dynamically (i.e., on the fly) or as a result ofpredetermining the boundaries of the selected node's bounded subgraph.

When the machine-independent optimization module determines that thechosen predecessor node has not been visited more than twice (i.e.,determination block 1012=“No”), the machine-independent optimizationmodule may determine whether to apply backwards optimizations on thechosen predecessor node in determination block 1018.

In an aspect, the machine-independent optimization module may determinewhether to apply backwards optimizations on the chosen predecessor nodebased on criteria similar to the ones the machine-independentoptimization module relies on when determining whether to applybackwards optimizations on the selected node in determination block 722of method 700 described above with reference to FIG. 7. For example, themachine-independent optimization module may determine whether the chosenpredecessor node includes dead or unreachable code.

When the machine-independent optimization module determines not to applybackwards optimizations on the chosen predecessor node (i.e.,determination block 1018=“No”), the machine-independent optimizationmodule may remove the chosen predecessor node from the predecessor listin block 1026. In an aspect, the machine-independent optimization modulemay not propagate backwards optimizations to the chosen predecessornode's predecessors in response to determining not to apply backwardsoptimizations to the chosen predecessor node.

When the machine-independent optimization module determines to applybackwards optimizations on the chosen predecessor node (i.e.,determination block 1018=“Yes”), the machine-independent optimizationmodule may apply backwards optimizations for the chosen predecessor nodein block 1020. For example, the machine-independent optimization modulemay apply dead code elimination techniques or other backwardsoptimizations.

In determination block 1022, the machine-independent optimization modulemay determine whether the chosen predecessor node is an entry node. Asdiscussed above, an entry node may indicate a stopping point in thepropagation of backwards optimizations. An entry node may be the startnode, a merge point, a source node, a phi node, or another node thatindicates a logical stopping point in backwards propagation. Thus, tostay within the boundaries of the selected node's bounded subgraph, themachine-independent optimization module may not propagate the backwardsoptimizations further than an entry node.

When the machine-independent optimization module determines that thechosen predecessor node is an entry node (i.e., determination block1022=“Yes”), the machine-independent optimization module may remove thechosen predecessor node from the predecessor list in block 1026.

On the other hand, when the machine-independent optimization moduledetermines that the chosen predecessor node is not an entry node (i.e.,determination block 1022=“No”), the machine-independent optimizationmodule may add the chosen predecessor node's predecessors to thepredecessor list in block 1024. In other words, the machine-independentoptimization module may continue propagating the backwards optimizationsto the chosen predecessor node's predecessors. The machine-independentoptimization module may also remove the chosen predecessor node from thepredecessor list in block 1026.

In determination block 1028, the machine-independent optimization modulemay determine whether the predecessor list is empty. In other words, themachine-independent optimization module may determine whether it hasfinished propagating backwards optimizations. When themachine-independent optimization module determines that the predecessorlist is not empty (i.e., determination block 1028=“No”), the process maycontinue in a loop as the machine-independent optimization module maycontinue performing method 1000 by selecting another predecessor node inthe predecessor list in block 1008 and perform the operations describedabove until the predecessor list is empty.

When the machine-independent optimization module determines that thepredecessor list is empty (i.e., determination block 1028=“Yes”), themachine-independent optimization module may continue with the operationsin method 700 by adding successors of the selected node to the readylist in block 728 as described above with reference to FIG. 7.

FIG. 11 illustrates an aspect method 1100 that may be implemented by amachine-independent optimization module for adding a selected node'ssuccessors to the ready list. The operations of method 1100 implement anaspect of the operations of block 728 of method 700 described above withreference to FIG. 7. The machine-independent optimization module maybegin performing method 1100 after propagating the backwardsoptimizations through the selected node's bounded subgraph in block 726of method 700 as described above with reference to FIG. 7.

In determination block 1102, the machine-independent optimization modulemay determine whether the selected node has a successor that has notbeen chosen. In an aspect, the machine-independent optimization modulemay determine whether any of the successor nodes have not yet beenchosen for processing. When the machine-independent optimization moduledetermines that all of the selected node's successors have been chosen(i.e., determination block 1102=“No”), the machine-independentoptimization module may continue with the operations in method 700 byremoving the selected node from the ready list in block 730 as describedabove with reference to FIG. 7.

On the other hand, when the machine-independent optimization moduledetermines that the selected node has a successor that has not beenchosen yet (i.e., determination block 1102=“Yes”), themachine-independent optimization module may choose a successor node inblock 1104. In an aspect, the machine-independent optimization modulemay choose the successor node based on a priority ordering, such as bynode type.

In determination block 1106, the machine-independent optimization modulemay determine whether the chosen successor node's predecessors have allbeen visited. In an aspect, a node may be added to the ready list as asuccessor node only when all of its predecessors have beenoptimized/visited. For example, if the selected node has a successornode that has a second predecessor node that has not yet been visited,the machine-independent optimization module may not add the chosensuccessor node to the ready list.

When the machine-independent optimization module determines that thechosen successor node's predecessors have all been visited (i.e.,determination block 1106=“Yes”), the machine-independent optimizationmodule may add the chosen successor node to the ready list in block1108. The process may continue in a loop until the machine-independentoptimization module determines that the selected node's successors haveall been chosen (i.e., determination block 1102=“No”).

On the other hand, when the machine-independent optimization moduledetermines that the chosen successor node has one or more predecessorsthat have not been visited (i.e., determination block 1106=“No”), themachine-independent optimization module may not add the chosen successornode to the ready list in block 1110. The process may continue in a loopuntil the machine-independent optimization module determines that theselected node's successors have all been chosen (i.e., determinationblock 1102=“No”).

FIGS. 12A and 12B illustrate aspect methods 1200, 1220 that may beimplemented by a machine-independent optimization module for adding anunvisited node to the ready list based on a sorting criterion. Theseaspect methods may have different compilation speeds and otherperformance trade-offs.

The operations of methods 1200, 1220 implement aspects of the operationsof block 734 of method 700 described above with reference to FIG. 7. Inan aspect, the machine-independent optimization module may beginperforming methods 1200, 1220 after determining that all nodes in thegraph have not been visited (i.e., determination block 736=“No”).

FIG. 12A illustrates an aspect method 1200 for adding an unvisited nodeto the ready list based on node type. In block 1202, themachine-independent optimization module may scan the graph for unvisitednodes. For example, the machine-independent optimization module maydiscover one or more nodes that are unreachable from the start node orare otherwise unconnected to the graph.

In determination block 1204, the machine-independent optimization modulemay determine whether there is a phi node that has not been visited. Inan aspect, phi nodes may have a higher priority than other types ofnodes. If the machine-independent optimization module determines thatthere is an unvisited phi node (i.e., determination block 1204=“Yes”),the machine-independent optimization module may select the unvisited phinode in block 1206. On the other hand, when the machine-independentoptimization module determines that there is no unvisited phi node(i.e., determination block 1204=“No”), the machine-independentoptimization module may select another unvisited node in block 1208. Forexample, the machine-independent optimization module may select acontrol flow node or a data node.

In block 1210, the machine-independent optimization module may add theselected node to the ready list. The machine-independent optimizationmodule may continue with the operations in method 700 by selectinganother node in the ready list in block 708 as described above withreference to FIG. 7.

FIG. 12B illustrates another aspect method 1220 for adding an unvisitednode to the ready list based a reverse postordering of the unvisitednodes. In block 1222, the machine-independent optimization module mayscan the graph for unvisited nodes. In block 1224, themachine-independent optimization module may sort the unvisited nodes inreverse postorder. In an aspect, the machine-independent optimizationmodule may order the unvisited nodes in a postordering and then mayreverse the postordering. The machine-independent optimization modulemay also select the first node in the reverse postordering in block1226. The machine-independent optimization module may also add theselected node to the ready list in block 1228.

The machine-independent optimization module may continue with theoperations in method 700 by selecting another node in the ready list inblock 708 as described above with reference to FIG. 7.

The various aspects may be implemented in any of a variety of computingdevices, an example of which is illustrated in FIG. 13. For example, thecomputing device 1300 may include a processor 1302 coupled to internalmemory 1304. Internal memory 1304 may be volatile or non-volatilememory, and may also be secure and/or encrypted memory, or unsecureand/or unencrypted memory, or any combination thereof. The processor1302 may also be coupled to a touch screen display 1306, such as aresistive-sensing touch screen, capacitive-sensing touch screen infraredsensing touch screen, or the like. Additionally, the display of thecomputing device 1300 need not have touch screen capability.Additionally, the computing device 1300 may have one or more antenna1308 for sending and receiving electromagnetic radiation that may beconnected to a wireless data link and/or cellular telephone transceiver1316 coupled to the processor 1302. The computing device 1300 may alsoinclude physical buttons 1312 a and 1312 b for receiving user inputs.The computing device 1300 may also include a power button 1318 forturning the computing device 1300 on and off.

The various aspects described above may also be implemented within avariety of computing devices, such as a laptop computer 1400 illustratedin FIG. 14. Many laptop computers include a touchpad touch surface 1417that serves as the computer's pointing device, and thus may receivedrag, scroll, and flick gestures similar to those implemented on mobilecomputing devices equipped with a touch screen display and describedabove. A laptop computer 1400 will typically include a processor 1411coupled to volatile memory 1412 and a large capacity nonvolatile memory,such as a disk drive 1413 of Flash memory. Additionally, the computer1400 may have one or more antenna 1408 for sending and receivingelectromagnetic radiation that may be connected to a wireless data linkand/or cellular telephone transceiver 1416 coupled to the processor1411. The computer 1400 may also include a floppy disc drive 1414 and acompact disc (CD) drive 1415 coupled to the processor 1411. In anotebook configuration, the computer housing includes the touchpad 1417,the keyboard 1418, and the display 1419 all coupled to the processor1411. Other configurations of the computing device may include acomputer mouse or trackball coupled to the processor (e.g., via a USBinput) as are well known, which may also be use in conjunction with thevarious aspects.

In the foregoing descriptions of the various embodiments the terms“optimize,” “optimizing” and “optimization” are used to refer toprocessing of source code that will improve its overall implementationcompared to its original presentation, and are not intended tocommunicate, infer or be construed as meaning that the processingresults in a theoretically optimum representation. To the contrary, thevarious embodiments result in improved, though not optimalrepresentations of source code using processes that are more efficientthan the conventional recursive forward and backward methods that canresult in an optimal intermediate representation of the source code,

The foregoing method descriptions and the process flow diagrams areprovided merely as illustrative examples and are not intended to requireor imply that the steps of the various aspects must be performed in theorder presented. As will be appreciated by one of skill in the art theorder of steps in the foregoing aspects may be performed in any order.Words such as “thereafter,” “then,” “next,” etc. are not intended tolimit the order of the steps; these words are simply used to guide thereader through the description of the methods. Further, any reference toclaim elements in the singular, for example, using the articles “a,”“an” or “the” is not to be construed as limiting the element to thesingular.

The various illustrative logical blocks, modules, circuits, andalgorithm steps described in connection with the aspects disclosedherein may be implemented as electronic hardware, computer software, orcombinations of both. To clearly illustrate this interchangeability ofhardware and software, various illustrative components, blocks, modules,circuits, and steps have been described above generally in terms oftheir functionality. Whether such functionality is implemented ashardware or software depends upon the particular application and designconstraints imposed on the overall system. Skilled artisans mayimplement the described functionality in varying ways for eachparticular application, but such implementation decisions should not beinterpreted as causing a departure from the scope of the presentinvention.

The hardware used to implement the various illustrative logics, logicalblocks, modules, and circuits described in connection with the aspectsdisclosed herein may be implemented or performed with a general purposeprocessor, a digital signal processor (DSP), an application specificintegrated circuit (ASIC), a field programmable gate array (FPGA) orother programmable logic device, discrete gate or transistor logic,discrete hardware components, or any combination thereof designed toperform the functions described herein. A general-purpose processor maybe a microprocessor, but, in the alternative, the processor may be anyconventional processor, controller, microcontroller, or state machine. Aprocessor may also be implemented as a combination of computing devices,e.g., a combination of a DSP and a microprocessor, a plurality ofmicroprocessors, one or more microprocessors in conjunction with a DSPcore, or any other such configuration. Alternatively, some steps ormethods may be performed by circuitry that is specific to a givenfunction.

In one or more exemplary aspects, the functions described may beimplemented in hardware, software, firmware, or any combination thereof.If implemented in software, the functions may be stored as one or moreinstructions or code on a non-transitory computer-readable storagemedium or non-transitory processor-readable storage medium (i.e., storedprocessor-executable software instructions). The steps of a method oralgorithm disclosed herein may be embodied in a processor-executablesoftware module and may be performed as processor-executableinstructions that may reside on a non-transitory computer-readable orprocessor-readable storage medium. Non-transitory computer-readable orprocessor-readable storage media may be any storage media that may beaccessed by a computer or a processor. By way of example but notlimitation, such non-transitory computer-readable or processor-readablestorage media may include RAM, ROM, EEPROM, FLASH memory, CD-ROM orother optical disk storage, magnetic disk storage or other magneticstorage devices, or any other medium that may be used to store desiredprogram code in the form of instructions or data structures and that maybe accessed by a computer. Disk and disc, as used herein, includescompact disc (CD), laser disc, optical disc, digital versatile disc(DVD), floppy disk, and blu-ray disc, where disks usually reproduce datamagnetically, while discs reproduce data optically with lasers.Combinations of the above are also included within the scope ofnon-transitory computer-readable and processor-readable media.Additionally, the operations of a method or algorithm may reside as oneor any combination or set of codes and/or instructions on anon-transitory processor-readable storage medium and/orcomputer-readable storage medium, which may be incorporated into acomputer program product.

The preceding description of the disclosed aspects is provided to enableany person skilled in the art to make or use the present invention.Various modifications to these aspects will be readily apparent to thoseskilled in the art, and the generic principles defined herein may beapplied to other aspects without departing from the spirit or scope ofthe invention. Thus, the present invention is not intended to be limitedto the aspects shown herein but is to be accorded the widest scopeconsistent with the following claims and the principles and novelfeatures disclosed herein.

What is claimed is:
 1. A method of optimizing an intermediaterepresentation of source code, comprising: generating a data dependencegraph from the intermediate representation, wherein the data dependencegraph comprises a plurality of nodes; selecting a node in the datadependence graph; applying an optimization to the selected node;recognizing a bounded subgraph of the data dependence graph based on theselected node; initializing a subgraph node list; adding successor andpredecessor nodes of the selected node in the bounded subgraph to thesubgraph node list; choosing a node from the subgraph node list;applying the optimization to the chosen node; determining whether thechosen node is an entry node or an exit node; adding successor andpredecessor nodes of the chosen node to the subgraph node list unless itis determined that the chosen node is the entry node or the exit node;and removing the chosen node from the subgraph node list.
 2. The methodof claim 1, wherein recognizing a bounded subgraph of the datadependence graph based on the selected node comprises: identifying theentry node, wherein the entry node is a predecessor node of the selectednode; scanning through the data dependence graph; determining whetherthe exit node is detected, wherein the exit node is a successor node ofthe selected node; and defining the bounded subgraph based on the entrynode and the exit node in response to determining that the exit node isdetected.
 3. The method of claim 1, wherein selecting a node in the datadependence graph comprises: initializing a ready list; adding a startnode to the ready list; selecting a node in the ready list; andincrementing a visitation counter of the selected node.
 4. The method ofclaim 3, wherein selecting a node in the ready list comprises:determining whether there is a control flow node in the ready list;selecting the control flow node in response to determining that acontrol flow node is in the ready list; and selecting a data node inresponse to determining that there are no control flow nodes in theready list.
 5. The method of claim 3, further comprising: for eachsuccessor of the selected node, determining whether predecessors of asuccessor node have all been visited; adding the successor node to theready list in response to determining that the successor node'spredecessors have all been visited; and removing the selected node fromthe ready list.
 6. The method of claim 3, wherein applying anoptimization to the selected node comprises determining whether theselected node has been visited more than twice, and wherein the methodfurther comprises: determining whether to apply a forwards optimizationon the selected node in response to determining that the selected nodehas not been visited more than twice; applying the forwards optimizationon the selected node in response to determining to apply the forwardsoptimization on the selected node; determining whether to apply abackwards optimization on the selected node in response to determiningthat the selected node has not been visited more than twice; andapplying the backwards optimization on the selected node in response todetermining to apply the backwards optimization.
 7. The method of claim6, further comprising: choosing a successor node from the subgraph nodelist; incrementing a visitation counter of the chosen successor node;determining whether the chosen successor node has been visited more thantwice; determining whether to apply the forwards optimization on thechosen successor node in response to determining that the chosensuccessor node has not been visited twice; applying the forwardsoptimization on the chosen successor node in response to determining toapply the forwards optimization; determining whether the chosensuccessor node is the exit node; adding successors of the chosensuccessor node to the subgraph node list unless it is determined thatthe chosen successor node is the exit node or it is determined not toapply the forwards optimization on the chosen successor node; andremoving the chosen successor node from the subgraph node list.
 8. Themethod of claim 6, further comprising: choosing a predecessor node fromthe subgraph node list; incrementing a visitation counter of the chosenpredecessor node; determining whether the chosen predecessor node hasbeen visited more than twice; determining whether to apply the backwardsoptimization on the chosen predecessor node in response to determiningthat the chosen predecessor node has not been visited twice; applyingthe backwards optimization on the chosen predecessor node in response todetermining to apply the backwards optimization; determining whether thechosen predecessor node is the entry node; adding a predecessor of thechosen predecessor node to the subgraph node list unless it isdetermined that the chosen predecessor node is the entry node or it isdetermined not to apply the backwards optimization on the chosenpredecessor node; and removing the chosen predecessor node from thesubgraph node list.
 9. The method of claim 3, further comprising:determining whether the ready list is empty; determining whether allnodes in the data dependence graph have been visited in response todetermining that the ready list is empty; and adding an unvisited nodeto the ready list in response to determining that all nodes in the datadependence graph have not been visited.
 10. The method of claim 1,further comprising: determining whether the subgraph node list is empty;and selecting another node in the subgraph node list in response todetermining that the subgraph node list is not empty.
 11. A computingdevice, comprising: a memory; and a processor coupled to the memory,wherein the processor is configured with processor-executableinstructions to perform operations comprising: generating a datadependence graph from an intermediate representation of source code,wherein the data dependence graph comprises a plurality of nodes;selecting a node in the data dependence graph; applying an optimizationto the selected node; recognizing a bounded subgraph of the datadependence graph based on the selected node; initializing a subgraphnode list; adding successor and predecessor nodes of the selected nodein the bounded subgraph to the subgraph node list; choosing a node fromthe subgraph node list; applying the optimization to the chosen node;determining whether the chosen node is an entry node or an exit node;adding successor and predecessor nodes of the chosen node to thesubgraph node list unless it is determined that the chosen node is theentry node or the exit node; and removing the chosen node from thesubgraph node list.
 12. The computing device of claim 11, wherein theprocessor is configured with processor-executable instructions toperform operations such that recognizing a bounded subgraph of the datadependence graph based on the selected node comprises: identifying theentry node, wherein the entry node is a predecessor node of the selectednode; scanning through the data dependence graph; determining whetherthe exit node is detected, wherein the exit node is a successor node ofthe selected node; and defining the bounded subgraph based on the entrynode and the exit node in response to determining that the exit node isdetected.
 13. The computing device of claim 11, wherein the processor isconfigured with processor-executable instructions to perform operationssuch that selecting a node in the data dependence graph comprises:initializing a ready list; adding a start node to the ready list;selecting a node in the ready list; and incrementing a visitationcounter of the selected node.
 14. The computing device of claim 13,wherein the processor is configured with processor-executableinstructions to perform operations such that selecting a node in theready list comprises: determining whether there is a control flow nodein the ready list; selecting the control flow node in response todetermining that a control flow node is in the ready list; and selectinga data node in response to determining that there are no control flownodes in the ready list.
 15. The computing device of claim 13, whereinthe processor is configured with processor-executable instructions toperform operations further comprising: for each successor of theselected node, determining whether predecessors of a successor node haveall been visited; adding the successor node to the ready list inresponse to determining that the successor node's predecessors have allbeen visited; and removing the selected node from the ready list. 16.The computing device of claim 13, wherein the processor is configuredwith processor-executable instructions to perform operations such thatapplying an optimization to the selected node comprises determiningwhether the selected node has been visited more than twice, and whereinthe processor is configured with processor-executable instructions toperform operations further comprising: determining whether to apply aforwards optimization on the selected node in response to determiningthat the selected node has not been visited more than twice; applyingthe forwards optimization on the selected node in response todetermining to apply the forwards optimization on the selected node;determining whether to apply a backwards optimization on the selectednode in response to determining that the selected node has not beenvisited more than twice; and applying the backwards optimization on theselected node in response to determining to apply the backwardsoptimization.
 17. The computing device of claim 16, wherein theprocessor is configured with processor-executable instructions toperform operations further comprising: choosing a successor node fromthe subgraph node list; incrementing a visitation counter of the chosensuccessor node; determining whether the chosen successor node has beenvisited more than twice; determining whether to apply the forwardsoptimization on the chosen successor node in response to determiningthat the chosen successor node has not been visited twice; applying theforwards optimization on the chosen successor node in response todetermining to apply the forwards optimization; determining whether thechosen successor node is the exit node; adding successors of the chosensuccessor node to the subgraph node list unless it is determined thatthe chosen successor node is the exit node or it is determined not toapply the forwards optimization on the chosen successor node; andremoving the chosen successor node from the subgraph node list.
 18. Thecomputing device of claim 16, wherein the processor is configured withprocessor-executable instructions to perform operations furthercomprising: choosing a predecessor node from the subgraph node list;incrementing a visitation counter of the chosen predecessor node;determining whether the chosen predecessor node has been visited morethan twice; determining whether to apply the backwards optimization onthe chosen predecessor node in response to determining that the chosenpredecessor node has not been visited twice; applying the backwardsoptimization on the chosen predecessor node in response to determiningto apply the backwards optimization; determining whether the chosenpredecessor node is the entry node; adding a predecessor of the chosenpredecessor node to the subgraph node list unless it is determined thatthe chosen predecessor node is the entry node or it is determined not toapply the backwards optimization on the chosen predecessor node; andremoving the chosen predecessor node from the subgraph node list. 19.The computing device of claim 13, wherein the processor is configuredwith processor-executable instructions to perform operations furthercomprising: determining whether the ready list is empty; determiningwhether all nodes in the data dependence graph have been visited inresponse to determining that the ready list is empty; and adding anunvisited node to the ready list in response to determining that allnodes in the data dependence graph have not been visited.
 20. Anon-transitory processor-readable storage medium having stored thereonprocessor-executable software instructions configured to cause aprocessor of a computing device to perform operations for optimizing anintermediate representation of source code, the operations comprising:generating a data dependence graph from the intermediate representation,wherein the data dependence graph comprises a plurality of nodes;selecting a node in the data dependence graph; applying an optimizationto the selected node; recognizing a bounded subgraph of the datadependence graph based on the selected node; initializing a subgraphnode list; adding successor and predecessor nodes of the selected nodein the bounded subgraph to the subgraph node list; choosing a node fromthe subgraph node list; applying the optimization to the chosen node;determining whether the chosen node is an entry node or an exit node;adding successor and predecessor nodes of the chosen node to thesubgraph node list unless it is determined that the chosen node is theentry node or the exit node; and removing the chosen node from thesubgraph node list.